package com.atguigu.gmall.common.util;

import com.atguigu.gmall.model.to.UserAuthTo;
import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;
import org.springframework.util.StringUtils;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @author A
 * @version 1.0
 * @description: TODO
 * @date 2025/9/10 0:37
 */
public class AuthUtil {

    public static UserAuthTo getAuthTo(){
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        UserAuthTo userAuthTo = new UserAuthTo();
        HttpServletRequest request = requestAttributes.getRequest();
        String userId = request.getHeader("UserId");
        if (!StringUtils.isEmpty(userId)&& !userId.isEmpty()) {
            userAuthTo.setUserId(Long.parseLong(userId));
        }
        String userTempId = request.getHeader("UserTempId");
        if (!StringUtils.isEmpty(userTempId)) {
            userAuthTo.setUserTempId(userTempId);
        };
        return userAuthTo;
    }
}
